# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Kaiting Chen <kaitocracy@gmail.com>
# Contributor: Gergely Imreh <imrehg@gmail.com>
# Contributor: champus
# Contributor: madeye
# Contributor: ranguvar
# Contributor: ninja_pt

pkgname=hwinfo
pkgver=22.2
pkgrel=2
pkgdesc='Hardware detection tool from openSUSE'
arch=(loong64 x86_64)
url='https://github.com/openSUSE/hwinfo'
license=(GPL2)
depends=('libx86emu=3.5' perl-xml-parser perl-xml-writer)
makedepends=(flex git sysfsutils)
options=(!emptydirs)
source=(custom_ioctl.patch
        "git+$url#commit=be6a9796a7d3497e25449c647304d555d5767cf4") # tag: 22.2
b2sums=('2b1bd3b53bbfc1e545e1a70ffd6cca08f704639a104928b2c02ccca3e82000f07a470fbdf129566ece6dfb2b98fdad0e82f18cc5c2016ebfeed043b4edb295b4'
        'SKIP')

prepare() {
  cd $pkgname
  patch -p1 -i ../custom_ioctl.patch
  echo touch changelog > git2log
  sed -i '/linux\/fs.h/d' src/hd/hd.c
}

build() {
  make -C $pkgname -j1 \
    CFLAGS+="-fPIC -I$srcdir/$pkgname/src/hd -w" \
    HWINFO_VERSION="$pkgver" \
    LIBDIR=/usr/lib
}

package() {
  cd $pkgname

  make DESTDIR="$pkgdir" LIBDIR=/usr/lib install
  mv "$pkgdir/usr/sbin" "$pkgdir/usr/bin"
  rmdir "$pkgdir/sbin"

  cd doc
  for f in *.1; do install -Dm644 $f "$pkgdir/usr/share/man/man1/$f"; done
  for f in *.8; do install -Dm644 $f "$pkgdir/usr/share/man/man8/$f"; done
}
